package com.springboot.core.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestController;

import com.springboot.core.common.Common;
import com.springboot.core.utils.StringUtils;

/**
 * 
 * 描述：Controller父类
 * @author 林海宁
 * @created 2019年1月31日 下午4:30:10
 * @since
 */
@RestController
public class BaseController extends Common {

    protected HttpServletResponse response;  
    
    protected HttpServletRequest request;  

    protected HttpSession session;  
    
    
    /**
     * ModelAttribute注解初始化对象
     * @param request
     * @param response
     */
    @ModelAttribute  
    public void setReqAndRes(HttpServletRequest request, HttpServletResponse response){  

        this.request = request;  

        this.response = response;  

        this.session = request.getSession();  

    }
    
    /**
     * 
     * 描述：获取参数并转化成字符串
     * @author 林海宁
     * @created 2019年1月31日 下午4:36:41
     * @since 
     * @param key key
     * @return 参数值
     */
    public String getParamCstring(String key){
    	return this.request.getParameter(key);
    }
    
    /**
     * 
     * 描述：获取参数值,值为空时返回默认值
     * @author 林海宁
     * @created 2019年1月31日 下午4:46:42
     * @since 
     * @param key key
     * @param defaultValue 默认值
     * @return 参数值
     */
    public String getParamCstring(String key,String defaultValue){
    	String str = this.request.getParameter(key);
    	if(StringUtils.isEmpty(str)){
    		return defaultValue;
    	}
    	return str;
    }
    
    
}
